package com.zwl.service.impl;

import java.util.List;
import java.util.Map;

import com.zwl.dao.MenuDao;
import com.zwl.dao.impl.MenuDaoImpl;
import com.zwl.po.MenuPo;
import com.zwl.po.PageBean;
import com.zwl.service.MenuService;

public class MenuServiceImpl implements MenuService {
	private MenuDao menuDao=new MenuDaoImpl();

	@Override
	public List<MenuPo> findByCondition(Map<String, Object> map) {
		List<MenuPo> list=menuDao.findByCondition(map);
		if(list!=null && list.size()>0){
			for(MenuPo m:list){
				if(m.getMenuParentId()!=null){
					m.setParentMenu(menuDao.findbyId(m.getMenuParentId()));
				}
			}
		}
		return list;
	}

	@Override
	public MenuPo findbyId(Integer id) {
		return menuDao.findbyId(id);
	}

	@Override
	public Integer[] saveMenu(MenuPo entity) {
		return menuDao.saveMenu(entity);
	}

	@Override
	public int updateMenu(MenuPo entity) {
		return menuDao.updateMenu(entity);
	}

	@Override
	public PageBean<MenuPo> findPageByCondition(int pageIndex, int pageSize, Map<String, Object> map) {
		PageBean<MenuPo> pagebean=menuDao.findPageByCondition(pageIndex, pageSize, map);
		if(pagebean!=null && pagebean.getList()!=null && pagebean.getList().size()>0){
			for(MenuPo m:pagebean.getList()){
				if(m.getMenuParentId()!=null){
					m.setParentMenu(menuDao.findbyId(m.getMenuParentId()));
				}
			}
		}
		return pagebean;
	}

}
